#!/user/bin/env python
# -*- coding: utf-8 -*-
"""
Author: Sjy
LastEditTime: 2024-08-30 10:30:45
Description: 警告提示对话框封装组件
"""

__all__ = []


from PySide2 import QtWidgets
from gui.controls import envs as envs


def warning(text: str = "", btnTitle: str = "关闭", parent=envs.GL.get_value("APP")):
    messageBox = QtWidgets.QMessageBox(parent)
    # messageBox.setStyleSheet("QLabel{"
    #                   "min-width: 50px;"
    #                   "text-align:right;"
    #                   "min-height: 300px; "
    #                   "font-size:14px;"
    #                   "}");
    messageBox.setWindowTitle("警告")
    messageBox.setText(f"{text or ''}")
    messageBox.setIcon(QtWidgets.QMessageBox.Warning)
    messageBox.setStandardButtons(QtWidgets.QMessageBox.Cancel)
    buttonN = messageBox.button(QtWidgets.QMessageBox.Cancel)
    buttonN.setText(btnTitle)
    messageBox.exec_()


def success(text: str = "", btnTitle: str = "关闭", parent=envs.GL.get_value("APP")):
    messageBox = QtWidgets.QMessageBox(parent)
    messageBox.setWindowTitle("提示")
    messageBox.setText(f"{text or ''}")
    messageBox.setIcon(QtWidgets.QMessageBox.Information)
    messageBox.setStandardButtons(QtWidgets.QMessageBox.Cancel)
    buttonN = messageBox.button(QtWidgets.QMessageBox.Cancel)
    buttonN.setText(btnTitle)
    messageBox.exec_()


def confirm(text: str = "", title="确认", sureText="是", cancelText="否", parent=envs.GL.get_value("APP")):
    messageBox = QtWidgets.QMessageBox(parent)
    messageBox.setWindowTitle(title)
    messageBox.setText(f"{text or ''}")
    messageBox.setIcon(QtWidgets.QMessageBox.Question)
    messageBox.setStandardButtons(
        QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel
    )
    buttonY = messageBox.button(QtWidgets.QMessageBox.Ok)
    buttonY.setText(sureText)
    buttonN = messageBox.button(QtWidgets.QMessageBox.Cancel)
    buttonN.setText(cancelText)
    reply = messageBox.exec()
    if reply == QtWidgets.QMessageBox.Ok:
        return True
    else:
        return False


def custom_warning(title: str = "", msg: str = "", show=False, parent=envs.GL.get_value("APP")) -> QtWidgets.QMessageBox:
    # 自定义警告对话框
    messageBox = QtWidgets.QMessageBox(parent)
    messageBox.setWindowTitle(title)
    messageBox.setText(msg)
    messageBox.setIcon(QtWidgets.QMessageBox.Warning)
    if show:
        messageBox.exec_()
    return messageBox


def select(title, label: str = "", options: dict = {}, parent=envs.GL.get_value("APP")):
    # 增加选择文本的通用对话框
    item, ok = QtWidgets.QInputDialog.getItem(
        parent, "选择", "测量数据类型:", options, 0, False
    )
    if ok:
        return item
